package com.reremouse.rerebbs.model;

import com.reremouse.rerebbs.dao.IBbsThreadDAO;
import com.reremouse.rerebbs.dao.IBbsZoneDAO;
import com.reremouse.util.SpringHelper;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "rerebbs_zone")
public class BbsZone
        implements Serializable {
    @Id
    @Column(name = "id", unique = true, nullable = false)
    private Long id = Long.valueOf(System.nanoTime());
    @Column(name = "name")
    private String name;
    @Column(name = "description")
    private String description;
    @Column(name = "genTime", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date genTime = new Date();
    @Column(name = "orderIndex")
    private Integer orderIndex;
    @Column(name = "if_only_mag")
    private boolean ifOnlyMag = false;
    @ManyToMany(cascade = {javax.persistence.CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinTable(name = "rerebbs_zonemag", joinColumns = {@javax.persistence.JoinColumn(name = "zone_id", referencedColumnName = "id")}, inverseJoinColumns = {@javax.persistence.JoinColumn(name = "user_id", referencedColumnName = "id")})
    private List<BbsUser> managers;
    @OneToMany(mappedBy = "zone", cascade = {javax.persistence.CascadeType.REMOVE}, fetch = FetchType.LAZY)
    List<BbsThread> threads;
    @Transient
    private String magsStr;
    @Transient
    private long threadCount;
    @Transient
    private BbsThread lastestThread;

    public BbsZone() {
    }

    public BbsZone(Long id, Date genTime) {
        this.id = id;
        this.genTime = genTime;
    }

    public BbsZone(Long id, String name, String description, Date genTime, Integer orderIndex) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.genTime = genTime;
        this.orderIndex = orderIndex;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getGenTime() {
        return this.genTime;
    }

    public void setGenTime(Date genTime) {
        this.genTime = genTime;
    }

    public Integer getOrderIndex() {
        return this.orderIndex;
    }

    public void setOrderIndex(Integer orderIndex) {
        this.orderIndex = orderIndex;
    }

    public List<BbsUser> getManagers() {
        return this.managers;
    }

    public void setManagers(List<BbsUser> managers) {
        this.managers = managers;
    }

    public List<BbsThread> getThreads() {
        return this.threads;
    }

    public void setThreads(List<BbsThread> threads) {
        this.threads = threads;
    }

    public boolean isIfOnlyMag() {
        return this.ifOnlyMag;
    }

    public void setIfOnlyMag(boolean ifOnlyMag) {
        this.ifOnlyMag = ifOnlyMag;
    }

    public long getThreadCount() {
        IBbsThreadDAO threadDAO = (IBbsThreadDAO) SpringHelper.getSpringBean("BbsThreadDAO");
        this.threadCount = threadDAO.findByZone(this.id.longValue()).size();
        return this.threadCount;
    }

    public void setThreadCount(long threadCount) {
        this.threadCount = threadCount;
    }

    public BbsThread getLastestThread() {
        IBbsZoneDAO zoneDAO = (IBbsZoneDAO) SpringHelper.getSpringBean("BbsZoneDAO");
        this.lastestThread = zoneDAO.findLatestThread(this.id.longValue());
        return this.lastestThread;
    }

    public void setLastestThread(BbsThread lastestThread) {
        this.lastestThread = lastestThread;
    }

    public String getMagsStr() {
        StringBuilder sb = new StringBuilder();
        for (BbsUser b : this.managers) {
            sb.append(b.getUsername());
            sb.append(",");
        }
        this.magsStr = sb.toString();
        return this.magsStr;
    }

    public void setMagsStr(String magsStr) {
        this.magsStr = magsStr;
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.model.BbsZone

 * JD-Core Version:    0.7.0.1

 */